﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LeEdu.MODEL;
using LeEdu.BLL;
using System.IO;
using LeEdu.Web.Common;
namespace LeEdu.Web.Controllers
{
    public class myController : Controller
    {
        //
        // GET: /my/

        /// <summary>
        /// 实例化CourseBLL
        /// </summary>
        CourseBLL coursebll = new CourseBLL();
        /// <summary>
        /// 实例化HourBLL
        /// </summary>
        HourBLL hourbll = new HourBLL();
        /// <summary>
        /// 实例化笔记BLL
        /// </summary>
        NoteBLL notebll = new NoteBLL();
        /// 实例化话题BLL
        /// </summary>
        TopicBLL topicbll = new TopicBLL();
        /// <summary>
        /// 我的教学首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 我的课程笔记
        /// </summary>
        /// <returns></returns>
        public ActionResult notebooks()
        {
            if (Session["User"]==null)
            {
                return Content("<script>alert('请先进行登录！');location.href='/Home/Index'</script>");
            }
            else{
                int uid = (Session["User"] as LeEdu.MODEL.UserInfo).UserInfoId;
                ViewBag.ud = uid;
                ViewBag.list = coursebll.getEntityList(p => true).Where(p => p.UserInfoId == uid).ToList();            
                return View();
            }            
        } 
        /// <summary>
        /// 我的课时笔记
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public ActionResult idnote(int id)
        {
            int ids = Convert.ToInt32(Session["id"]);
            var c = coursebll.getEntity(p => p.CoursesId == id);
            ViewBag.cn = c.CoursesName;
            ViewBag.ci = c.CImage;
            var uid = (Session["User"] as LeEdu.MODEL.UserInfo).UserInfoId;            
            ViewBag.ln = notebll.getEntityList(p => true).Where(p => (p.UserInfoId == uid) && (p.CoursesID == id)).ToList();
            return View();
        }
        /// <summary>
        /// 删除我的笔记 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult delete(int id)
        {
            
           
            bool s = notebll.Del(notebll.getEntity(t => t.ID == id));
            if(s)
            {
                return  Content("<script>alert('确定要删除吗？');location.href='/my/notebooks'</script>");
            }
            else
            {

                return Content("<script>alert('请先进行登录！');location.href='/my/Index'</script>");
            }
                       
        }
        /// <summary>
        /// 我的课程话题
        /// </summary>
        /// <returns></returns>
        public ActionResult discussions()
        {             
            var uid = (Session["User"] as LeEdu.MODEL.UserInfo).UserInfoId;
            List<LeEdu.MODEL.Topic> tt=topicbll.getEntityList(p => true).Where(p => p.UserInfoId == uid).ToList();
            ViewBag.ltt = tt.Count();
            ViewBag.lt = tt;
            return View();
        }
    }
}
